<!--{__NOLAYOUT__}-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="__STATIC__/js/layui/css/layui.css">
</head>
<body>


<div style="margin: 5px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">书籍封面</label>
            <div class="layui-input-inline">
                <img id="book-img" style="width: auto;height: auto;max-width: 100%;max-height: 100%;"  src="{$book_img}" alt="书籍封面">
                <input type="hidden" value="{$book_img}" name="book_img">
                <input type="hidden" value="{$book_id}" name="book_id">

            </div>
            <button type="button" class="layui-btn" id="upload-header">
                <i class="layui-icon">&#xe67c;</i>上传封面
            </button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">书籍名称</label>
            <div class="layui-input-inline">
                <input type="text" name="book_name" value="{$book_name}" placeholder="书籍名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">书籍分类</label>
            <div class="layui-input-inline">
                <select name="classify" lay-verify="required">
                    <option value="" selected></option>
                    {volist name="classify" id="vo"}
                    {if  $c_id == $vo.id}
                    <option value="{$vo.id}" selected>{$vo.name}</option>
                    {else /}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/if}
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-inline">
                <input type="text" name="book_auth" value="{$book_auth}" placeholder="作者" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出版社</label>
            <div class="layui-input-inline">
                <input type="text" name="book_man" value="{$book_man}" placeholder="出版社" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-inline">
                <textarea name="book_dec" placeholder="请输入小于300字的内容" class="layui-textarea">{$book_dec}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">书籍数量</label>
            <div class="layui-input-inline">
                <input type="number" value="{$book_num}" name="book_num" placeholder="书籍数量" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
            </div>
        </div>
    </form>
</div>
<input type="hidden" name="name" value="lalal">
<script src="__STATIC__/js/layui/layui.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.min.js" charset="utf-8"></script>


<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload-header' //绑定元素
            ,url: '/admin/books/upload' //上传接口
            ,accept:'images'
            ,acceptMime:'image/*'
            ,done: function(res){
                //上传完毕回调
                $('#book-img').attr('src', res.data.src);
                $('input[name="book_img"]').val(res.data.src);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    layui.use('form', function(){
        var form = layui.form;
        var $ = layui.$;
        //监听提交
        form.on('submit(formDemo)', function(data){
            var postdata = data.field;




            $.ajax({
                type: 'post'
                , dataType: 'json'
                , url: '/admin/books/edit'
                , data: postdata
                , success: function (obj) {
                    if (obj.code === -1) {
                        layer.msg(obj.msg);
                    } else if (obj.code === 1) {
                        parent.layer.close(index);
                    }

                }
            });
            return false;
        });
    });
</script>
</body>
</html>